package lib.bone.flow.module.processor.impl;

import cn.hutool.core.lang.Validator;
import lib.bone.flow.constant.FlowNodeTypeConst;
import lib.bone.flow.domain.dto.FlowParam;
import lib.bone.flow.domain.entity.FlowWork;
import lib.bone.flow.domain.model.BaseModel;
import lib.bone.flow.domain.model.EndModel;
import lib.bone.flow.domain.model.FlowModel;
import lib.bone.flow.domain.model.StartModel;
import lib.bone.flow.event.FlowEndNodeEvent;
import lib.bone.flow.module.processor.FlowNodeProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class EndNodeProcessorImpl implements FlowNodeProcessor {

    @Autowired(required = false)
    FlowEndNodeEvent flowEndNodeEvent;

    @Override
    public String getNodeType() {
        return FlowNodeTypeConst.END_NODE;
    }

    @Override
    public void process(FlowWork flowWork, FlowModel flowModel, BaseModel currentNddeModel, FlowParam flowParam) {
        if (Validator.isNotEmpty(flowEndNodeEvent)){
            EndModel endModel = flowModel.getEndModel();
           // StartModel startModel = flowModel.getStartModel();
            flowEndNodeEvent.onEvent(flowWork,endModel,flowParam);
        }
    }

    @Override
    public void back(FlowWork flowWork, FlowModel flowModel, BaseModel currentNddeModel, FlowParam flowParam) {
        log.warn("执行到终点的流程实例，无法倒退");
    }
}
